I’ve got arrays nested like this:
[["1", "apple 1"], ["1", "pear 2"], ["2", "lemon 1"], ["12", "lemon 12"]]
I’d like to replace all the occurrences of 1, 2, and 12 at nested array index 0 with "one", "two", and "twelve" respectively, so the result is this:
[["one", "apple 1"], ["one", "pear 2"], ["two", "lemon 1"], ["twelve", "lemon 12"]]
How do I do it?
Array indexes are actually strings, that’s why
numbers['2']('2'being a string) would retrieve the third member.To iterate over the array, you could use a
for-loop, butforEachlooks nicer.