JSON.stringfy()

김_리트리버·2020년 8월 24일
0

기타꿀팁

목록 보기
2/14

JSON.stringfy()

  • 기본적으로 JSON 문자열을 리턴
  • replacer, space 등을 지정하여 리턴되는 문자열을 변경할 수 있다.

// JSON.stringify(value[, replacer[, space]])
// replacer = 리턴될 JSON 에 포함시킬 type을 지정한다.
//null -> 모든 type 이 리턴됨 
// space = stringfy 된 json 문자열의 공백을 지정 / 보통 2이상
      

  function replacer(key, value) {
    if (typeof value === 'string') return undefined
    return value
  }

  let exampleJSON = {capibara:'카피바라',age:29}
  JSON.stringify(exampleJSON,replacer) // '{"age":29}'    

profile
web-developer

0개의 댓글