Tuna Tuna - 1 year ago 120
Javascript Question

Lodash loop through an array of arrays

I have an array with other arrays

[ ["1","13052033555","4444444","40000",1461575799,"1"],

Question: Using Lodash how can I loop through the values of each inner array and only apply a method to the 5th and 2nd?

Answer Source

Why do you need lodash? You can do it in plain Javascript. Let's suppose your array is called arr:

for (var i = 0; i < arr.length; i++) {

This will apply a method to second and fifth element of each array.

If you want, instead (sorry, your question isn't clear), apply a method to each element of the second and fifth array you do something like this:

for (let i = 0; i < arr[2].length; i++) {

for (let i = 0; i < arr[5].length; i++) {
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download