URLSearchParams 사용하기

Young Thirty·2022년 1월 15일

URL에서 쿼리스트링 가져오기

URL :: http://localhost:3000/data/productList/?name=Nike&price=100

const location = location.seach
console.log(locatoin) //출력 = ?name=Nike&price=100

쿼리 스트링 객체로 변환하기

  • 이유: 쉽게 수정하기 위해서
const location = location.seach
const qs = new URLSearchParams(location)

키워드 값 호출하기(get)

const location = location.seach
const qs = new URLSearchParams(location)

qs.get('name') //출력= Nike

키워드 값 변경(set_변경 후 다시 스트링으로 변환)

qs.set('nmae', 'adidas') 
qs.toString()  // 출력= ?name=adidas&price=100

https://developer.mozilla.org/ko/docs/Web/API/URLSearchParams

0개의 댓글