TIL | Concat, indexOf, includes & reverse

ryan·2020년 11월 18일
0

JavaScript

목록 보기
7/23
post-thumbnail

➕ More Array Methods

  • concat - merge arrays
  • includes - look for a value
  • indexOf - just like string.indexOf
  • reverse - reverses an array

💑 concat() - merge arrays

let cats = ['blue', 'kitty']
let dogs = ['rusty', 'wyatt']

cats.concat(dogs); // ["blue", "kitty", "rusty", "wyatt"]
dogs.concat(cats); // ["rusty", "wyatt", "blue", "kitty"]

cats // ['blue', 'kitty']
dogs // ['rusty', 'wyatt']

let comboParty = dogs.concat(cats);

comboParty // ["rusty", "wyatt", "blue", "kitty"]

👻 includes() - look for a value

let cats = ['blue', 'kitty']

cats.includes('blue') // true
cats.includes('Blue') // false

🎐 indexOf() - just like string.indexOf

"Blue".indexOf('B') // 0
"Blue".indexOf('e') // 3
"Blue".indexOf('0') // -1

comboParty // ["rusty", "wyatt", "blue", "kitty"]

comboParty.indexOf('rusty') // 0
comboParty.indexOf('kitty') // 3
comboParty.indexOf('ASDQWEZXC') // -1

💔 reverse() - reverses an array

comboParty // ["rusty", "wyatt", "blue", "kitty"]

comboParty.reverse(); // ["kitty", "blue", "wyatt", "rusty"]

comboParty // ["kitty", "blue", "wyatt", "rusty"]

comboParty.push("blue"); // ["kitty", "blue", "wyatt", "rusty", "blue"]
comboParty.indexOf('blue') // 1
profile
👨🏻‍💻☕️ 🎹🎵 🐰🎶 🛫📷

0개의 댓글