<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Samiul Lesum</title>
    <description>The latest articles on DEV Community by Samiul Lesum (@lesumsam).</description>
    <link>https://dev.to/lesumsam</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F212368%2F844bbb2e-46a7-4719-a23b-c1dd3b143a40.jpg</url>
      <title>DEV Community: Samiul Lesum</title>
      <link>https://dev.to/lesumsam</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/lesumsam"/>
    <language>en</language>
    <item>
      <title>Some useful array methods in JavaScript</title>
      <dc:creator>Samiul Lesum</dc:creator>
      <pubDate>Fri, 04 Oct 2019 14:47:46 +0000</pubDate>
      <link>https://dev.to/lesumsam/some-useful-array-methods-in-javascript-jnf</link>
      <guid>https://dev.to/lesumsam/some-useful-array-methods-in-javascript-jnf</guid>
      <description>&lt;p&gt;The JavaScript Array object is a global object; which are high-level, list-like objects. The following array methods are essential to know to work as a javascript developer. &lt;/p&gt;

&lt;p&gt;Array.concat(): The concat() method is used to join two or more arrays.&lt;/p&gt;

&lt;p&gt;const num1 = [1, 2, 3];&lt;br&gt;
const num2 = [4, 5, 6];&lt;br&gt;
const numbers = num1.concat(num1, num2);&lt;br&gt;
console.log(numbers); &lt;br&gt;
// results in [1, 2, 3, 4, 5, 6]&lt;/p&gt;

&lt;p&gt;Array.map(): The map() method creates a new array with the results of calling a provided function on every element in the calling array.&lt;br&gt;
Syntax: array.map(function(currentValue, index, arr), thisValue)&lt;br&gt;
currentValue (required): The value of the current element.&lt;br&gt;
index (optional): The array index of the current element.&lt;br&gt;
arr (optional): The array object the current element belongs to.&lt;br&gt;
thisValue (optional): A value to be passed to the function to be used as its "this" value. If this parameter is empty, the value "undefined" will be passed as its "this" value.&lt;/p&gt;

&lt;p&gt;var array1 = [1, 4, 9, 16];&lt;br&gt;
// pass a function to map&lt;br&gt;
const map1 = array1.map(x =&amp;gt; x * 2);&lt;br&gt;
console.log(map1);&lt;br&gt;
// expected output: Array [2, 8, 18, 32]&lt;/p&gt;

&lt;p&gt;Array.reduce(): The reduce() method executes a reducer function (that you provide) on each element of the array, resulting in single output value.&lt;br&gt;
Syntax: arr.reduce(callback(accumulator, currentValue[, index[, array]])[, initialValue]).&lt;br&gt;
callback: A function to execute on each element in the array (except for the first, if no initialValue is supplied), taking four arguments:&lt;br&gt;
accumulator: The accumulator accumulates the callback's return values. &lt;br&gt;
currentValue: The current element being processed in the array.&lt;br&gt;
index (optional): The index of the current element being processed in the array. &lt;br&gt;
array (optional): The array reduce() was called upon.&lt;br&gt;
initialValue (optional): A value to use as the first argument to the first call of the callback. If no initialValue is supplied, the first element in the array will be used and skipped.&lt;/p&gt;

&lt;p&gt;var sum = [0, 1, 2, 3].reduce(function (accumulator, currentValue) {&lt;br&gt;
  return accumulator + currentValue;&lt;br&gt;
}, 0);&lt;br&gt;
// sum is 6&lt;/p&gt;

&lt;p&gt;Array.slice(): The slice() method returns the selected elements in an array, as a new array object. The slice() method selects the elements starting at the given start argument, and ends at, but does not include, the given end argument.&lt;br&gt;
Note: The original array will not be changed.&lt;/p&gt;

&lt;p&gt;var arr = [1, 2, 3, 4, 5];&lt;br&gt;
console.log(arr.slice(2));&lt;br&gt;
// expected output: Array [3, 4, 5]&lt;br&gt;
console.log(arr.slice(2, 4));&lt;br&gt;
// expected output: Array [3, 4]&lt;/p&gt;

&lt;p&gt;Array.splice(): The splice() method adds/removes items to/from an array, and returns the removed item(s).&lt;br&gt;
Note: This method changes the original array.&lt;/p&gt;

&lt;p&gt;var arr = [1, 3, 4, 6];&lt;br&gt;
arr.splice(1, 0, 2);&lt;br&gt;
// inserts at index 1&lt;br&gt;
console.log(arr);&lt;br&gt;
// expected output: Array [1, 2, 3, 4, 6]&lt;br&gt;
arr.splice(4, 1, 6);&lt;br&gt;
// replaces 1 element at index 4&lt;br&gt;
console.log(arr);&lt;br&gt;
// expected output: Array [1, 2, 3, 4, 5]&lt;/p&gt;

&lt;p&gt;Array.shift(): The shift() method removes the first item of an array.&lt;br&gt;
Note: This method changes the length of the array.&lt;/p&gt;

&lt;p&gt;var arr = [0, 1, 2, 3, 4, 5];&lt;br&gt;
console.log(arr.shift());&lt;br&gt;
// expected output: Array [1, 2, 3, 4, 5]&lt;/p&gt;

&lt;p&gt;Array.unshift(): The unshift() method adds new items to the beginning of an array and returns the new length.&lt;br&gt;
Note: This method changes the length of an array.&lt;/p&gt;

&lt;p&gt;var arr = [2, 3, 4, 5];&lt;br&gt;
console.log(arr.unshift(1));&lt;br&gt;
// expected output: Array [1, 2, 3, 4, 5]&lt;/p&gt;

&lt;p&gt;Array.push(): The push() method adds new items to the end of an array and returns the new length.&lt;br&gt;
Note: This method changes the length of the array.&lt;/p&gt;

&lt;p&gt;var arr = [1, 2, 3, 4];&lt;br&gt;
console.log(arr.push(5));&lt;br&gt;
// expected output: Array [1, 2, 3, 4, 5]&lt;/p&gt;

&lt;p&gt;Array.pop(): The pop() method removes the last element from an array and returns that element. This method changes the length of the array.&lt;/p&gt;

&lt;p&gt;var arr = [1, 2, 3, 4];&lt;br&gt;
console.log(arr.pop());&lt;br&gt;
// expected output: Array [1, 2, 3, 4]&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>webdev</category>
    </item>
  </channel>
</rss>
