Monday, June 3, 2024
 Popular · Latest · Hot · Upcoming
51
rated 0 times [  53] [ 2]  / answers: 1 / hits: 57536  / 8 Years ago, sat, july 9, 2016, 12:00:00

I have an array of objects,



var out = [{
type: 1,
from: 13052033555,
to: 4444444,
amount: 40000,
date: 1461575799,
status: 1
}, {
type: 2,
from: 13052033555,
to: 1111111,
amount: 30000,
date: 1461575884,
status: 1
}...
];


I get only it's values without keys



Now i used this function to get the values from array like this,
I pass array then it returns only values without keys



function foo(a) {
var values = [];
for (var i = 0; i < a.length; i++) {
var obj = a[i];
var arr = Object.keys(obj).map(function(k) {
return obj[k]
});
values.push([ + arr + ],);
}
return values.join('');
}


Then it returns the values data without keys like this,



[ [1,13052033555,4444444,40000,1461575799,1],
[2,13052033555,1111111,30000,1461575884,1],
....]


Question: How can i change my foo function to lodash?


More From » arrays

 Answers
140

Use _.values()





    var out = [{
type: 1,
from: 13052033555,
to: 4444444,
amount: 40000,
date: 1461575799,
status: 1
}, {
type: 2,
from: 13052033555,
to: 1111111,
amount: 30000,
date: 1461575884,
status: 1
}
];

for (var i = 0; i < out.length; i++) {
out[i] = _.values(out[i]);
}


console.log(out)

<script src=https://cdn.jsdelivr.net/lodash/4.13.1/lodash.min.js></script>




[#61445] Thursday, July 7, 2016, 8 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
zahrafrancisr

Total Points: 176
Total Questions: 105
Total Answers: 99

Location: Svalbard and Jan Mayen
Member since Sun, Sep 25, 2022
2 Years ago
;