split, splice, slice

모든 js 메소드는 mdn 공식문서를 참고하자 !!

정말 비슷하게 생겨서 자꾸 헷갈리게 하는 친구들

split

String.prototype.split()

The split() method divides a String into an ordered list of substrings, puts these substrings into an array, and returns the array. The division is done by searching for a pattern; where the pattern is provided as the first parameter in the method's call.

> split의 syntax

split()
split(separator)
split(separator, limit)

splice

Array.prototype.splice()

The splice() method changes the contents of an array by removing or replacing existing elements and/or adding new elements in place. To access part of an array without modifying it, see slice().

> splice의 syntax

splice(start)
splice(start, deleteCount)
splice(start, deleteCount, item1)
splice(start, deleteCount, item1, item2, itemN)

slice

slice -> Array 일때

Array.prototype.slice()

The slice() method returns a shallow copy of a portion of an array into a new array object selected from start to end (end not included) where start and end represent the index of items in that array. The original array will not be modified.

> slice의 syntax

slice()
slice(start)
slice(start, end)

slice -> String 일때

String.prototype.slice()

The slice() method extracts a section of a string and returns it as a new string, without modifying the original string.

> slice의 syntax

slice(beginIndex)
slice(beginIndex, endIndex)

좋은 웹페이지 즐겨찾기