0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

【jquery javascript】多次元配列を指定したキーと値にする方法

Last updated at Posted at 2021-09-02
process.stdin.resume();
process.stdin.setEncoding('utf8');

const Equipment = [
{name: "", value: "どうのつるぎ"},
{name: "防具", value: "かわのたて"},
{name: "防止", value: "かわのぼうし"},
{name: "ナイフ", value: "ブロンズナイフ"}
];

data = Equipment.reduce(function(p,c){
        if(p[c['name']] === undefined){
          p[c['name']] = [];
        }
        p[c['name']].push(c['value']|0);
            return p;
}, {});

console.log(data);

#結果 ⇛ 連想配列になる

{
  '剣': [ 'どうのつるぎ' ],
  '防具': [ 'かわのたて' ],
  '防止': [ 'かわのぼうし' ],
  'ナイフ': [ 'ブロンズナイフ' ]
}

var player ={name: "Ronaldo", team: "Juventus"};

player.uniNumber = 7;

console.log(player);

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?