𝗔𝗿𝗿𝗮𝘆 𝗠𝗲𝘁𝗵𝗼𝗱𝘀 𝗶𝗻 𝗝𝗮𝘃𝗮𝗦𝗰𝗿𝗶𝗽𝘁
JavaScript provides many tools to manage lists of data. You use these methods to add, remove, or change items in your arrays.
Here are the essential methods you need to know:
• length property This tells you the number of items in your array. It updates every time you add or remove an item. Example: let a = ["HTML", "CSS", "JS", "React"]; (a.length is 4)
• toString() method This turns your array into a string. Each item stays separated by a comma.
• join() method This creates a new string from your array. You pick a specific separator to put between items.
• push() method This adds a new item to the end of your array.
• pop() method This removes the last item from your array.
• shift() method This removes the first item from your array. All other items move up one position.
• map() method This creates a new array. It runs a specific function on every single item in your original list. This method does not change your original array.
Test your knowledge: What is the output of this code? let a = ["HTML", "CSS", "JS", "React"]; console.log(a.length);
Write your answer in the comments.
Source: https://dev.to/karthick_07/array-methods-in-javascript-2lib