substring

  • str.substring(indexStrat[, indexEnd])
  • indexStart의 위치부터 indexEnd 전까지의 문자열을 반환한다.
let str = "hello world!"

str.substring(2, 4) //'ll'
str.substring(6) //'world!'
str.substring(5, -1) //'hello'

//음수를 줄 경우 indexStart전 위치부터 0번째 인덱스까지의 문자를 반환

 

concat

  • 주어진 배열이나 값들을 기존 배열에 합쳐서 새 배열을 반환한다.
let arr = [1, 2, 3, 4]
let dubleArr = [[5, 6], [7, 8]]

arr.concat(dubleArr) //[ 1, 2, 3, 4, [ 5, 6 ], [ 7, 8 ] ]
arr.concat(...dubleArr) //[ 1, 2, 3, 4, 5, 6, 7, 8 ]

'학습' 카테고리의 다른 글

Object ↔ Array 변환  (0) 2021.08.20
React - props, state  (0) 2021.08.17
compose 추상화  (0) 2021.08.10
map, filter, reduce  (0) 2021.08.10
Shallow copy / Deep copy  (0) 2021.08.05