search

Home  >  Q&A  >  body text

node.js - How to get a collection of values ​​in a dictionary structure?

> a = {"1":[1,2,3], "2":[2,3,4], "3":[3,4,5]}
{ '1': [ 1, 2, 3 ],
  '2': [ 2, 3, 4 ],
  '3': [ 3, 4, 5 ] }
> Object.keys(a)
[ '1', '2', '3' ]
>

Excuse me, is there a way to get the value set [[1,2,3],[2,3,4],[3,4,5]]?

我想大声告诉你我想大声告诉你2868 days ago895

reply all(3)I'll reply

  • 滿天的星座

    滿天的星座2017-05-16 13:23:43

    Object.keys(a).map(k => a[k])

    reply
    0
  • 我想大声告诉你

    我想大声告诉你2017-05-16 13:23:43

    I usually use this kindunderscore

    npm install underscore --save
    var _ = require('underscore');
    var a = {"1":[1,2,3], "2":[2,3,4], "3":[3,4,5]};
    var values = _.values(a);
    console.log(values);

    reply
    0
  • 高洛峰

    高洛峰2017-05-16 13:23:43

    First of all, the dictionary is unordered, so the obtained set is also unordered. It is the default order of the browser
    You can use for in

    var arr = [];
    var cont = 0;
    for(var i in a){
        for(var j=0; j<a[i].length;j++){
            arr[cont].push(a[i][j])
        }
        cont++;
    }
    console.log(arr)

    There will definitely be no problem with compatibility like this

    reply
    0
  • Cancelreply