javascript : reduce :: Array to other primative or Object etc.

Darcy Daeseok YU ·2023년 6월 6일
0

Cookie Parser 구현 중 produce의 사용법이 궁금해졌음.
Starting with the Curiosity of produce which is one of the prototype functions of Array.

const beTargeted = {};
const cookieParser = (cookiestr = "") => {
  return cookiestr
    .split(";")
    .map((cookie) => cookie.split("="))
    .reduce((target, [K, V]) => {
      // console.log(target, K, V);
      target[K] = V;
      return target;
    }, beTargeted);
};

profile
React, React-Native https://darcyu83.netlify.app/

0개의 댓글