Top popular JavaScript array methods.
concat()
['π', 'π'].concat('π©') // Output: (3)Β ["π", "π", "π©"]
join()
['π¨βπ¦³', 'π©βπ¦³'].join('π') // Output: "π¨βπ¦³ππ©βπ¦³"
slice()
["π", "π", "π©"].slice(2) // Output: ["π©"]
indexOf()
["π", "π", "π₯Ά"].indexOf('π') // Output: 1
lastIndexOf()
["π", "π", "π"].lastIndexOf('π') // Output: 2
reverse()
["π", "π", "π₯Ά"].reverse() // Output: (3)Β ["π₯Ά", "π", "π"]
sort()
["π¨", "π΄", "π¦"].sort() // Output: (3)Β ["π¦", "π¨", "π΄"]
shift()
["π¦", "π¨", "π΄"].shift() // Output: (2)Β ["π¨", "π΄"]
unshift()
["π¦", "π¨", "π΄"].unshift('π©'); // Output: (4)Β ["π©", "π¦", "π¨", "π΄"]
pop()
["π¦", "π¨", "π΄"].pop(); // Output: (2)Β ["π¦", "π¨"]
push()
["π¦", "π¨", "π΄"].push('π₯'); // Output: (4)Β ["π¦", "π¨", "π΄", "π₯"]
filter()
["π¦", "π¨", "π΄"].filter(person => person == 'π¨') // Output: ["π¨"]
includes()
["π¦", "π¨", "π΄"].includes('π¦') // Output: true
Hope this will help you to mess with array.
You can suggest if I missed any thing. Also share suggestion for any other cheat sheet.
Happy.Code()
Top comments (0)