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)