javaScript

ARRAY METHODS ์™€ ์—ฌ๋Ÿฌ METHODS

innieve 2022. 9. 20. 00:31

JS Arrays๋ž€?

- colletion of things

๋…๋ฆฝ๋œ ๋ณ€์ˆ˜๋“ค์„ ํ•˜๋‚˜์˜ ๊ทธ๋ฃน์œผ๋กœ ๋ฌถ์–ด์คŒ

ex) ์ผ์ฃผ์ผ ๋™์•ˆ ๋จน์„ ์ˆ˜ ์žˆ๋„๋ก 7์นธ์œผ๋กœ ๋‚˜๋‰˜์–ด์ง„ ์•ฝํ†ต

 

1. ๋ฐฐ์—ด์€ ๊ฐ’์€ ์ง‘ํ•ฉ์ด๋‹ค.

2. ๋ฐฐ์—ด์˜ ๊ฐ’์€ ์ˆœ์„œ์žˆ๋Š” ์ง‘ํ•ฉ์ด๋‹ค.

- [ ] ๋Œ€๊ด„ํ˜ธ ์‚ฌ์šฉ

- 0๋ถ€ํ„ฐ ์‹œ์ž‘

- type of  = 'object'

 


ARRAY METHODS

  • Push - add to end
  • Pop - remove from end
  • Shift - remove from start
  • Unshift - add to start 

 


MORE METHODS

  • concat - merge arrays
  • includes - look for a value
  • indexOf - just like string.indexOf
  • join - creates a string from an array
  • reverse - reverses an array
  • slice - copies a portion on an array
  • splice - removes/replaces elements
  • sort - sorts an array

# concat

cats.concat(dogs)

๋จผ์ € ์ ์–ด ์ค€ ๋ณ€์ˆ˜๊ฐ€ ์•ž์— ๋‚˜์˜จ๋‹ค.

 

 

# includes

includes๋Š” boolean methods๋ผ์„œ true ์™€ false ๋‘ ๊ฐ€์ง€ ๊ฐ’๋งŒ ๋ฐ˜ํ™˜ํ•œ๋‹ค.

์ด ๋•Œ ๋Œ€,์†Œ๋ฌธ์ž๋„ ๊ตฌ๋ถ„ํ•จ.

 

# indexOf

 

 

# reverse

 

 

# slice

 

 

# splice

 

 

# sort