0

Been a long time reader of Stack overflow but have never joined and asked a question but I guess there's a first time for everything.

I'm currently having an issue with an array in JS that is being used to store Twitter, Instagram and Pinterest feeds, as well as their timestamps.

Here is how the array was created...

var array = [];

Here is an example of how the feed and time is inserted into the array...

for (i < 0; i < 10; i++) {
array[i] = [feed, time] };

The array I'm getting looks something like this...

[[0[0][1]]]
[[1[0][1]]]
[[2[0][1]]]

When I console log the following...

console.log(array[[5]]);

I get this response...

["<a href="http://www.twi...ontrolled through diet.", "145339"]

How can I get the "145339" part just by itself?

I tried "console.log(array[[5[1]]])" but I get the message "undefined".

Dally
  • 1,281
  • 4
  • 18
  • 37
  • 1
    You probably want `array[5][1]`. `array[[5]]` is the same as `array[5]` by coincidence, but `array[[5[1]]]` is just wrong. – Felix Kling Feb 08 '13 at 15:15
  • `array[[5]]` and `array[[5[1]]]` don't make sense. – Paul S. Feb 08 '13 at 15:15
  • possible duplicate of [I have a nested data structure / JSON, how can I access a specific value?](http://stackoverflow.com/questions/11922383/i-have-a-nested-data-structure-json-how-can-i-access-a-specific-value) – Felix Kling Feb 08 '13 at 15:17

2 Answers2

2

For accessing members of a multidimensional array, the syntax you are looking for is more like array[5][1]. I can't tell from your code exactly what the correct answer is but it looks like your syntax is the issue.

marteljn
  • 6,446
  • 3
  • 30
  • 43
0

Use the split() method of javascript

var part = array[[5]];
var arr = part.split(',')
console.log(arr[1]);
Talha
  • 18,898
  • 8
  • 49
  • 66
  • while `[0,1,2,3,4,5,6][[5]]` is `5`, `[[5]]` is not how you should select the index because it is reaching the key `'5'` by doing `[5].toString()`. – Paul S. Feb 08 '13 at 15:21
  • @PaulS. may be you are right, but in his question he said, he reached in following console.log(array[[5]]); to get response [" – Talha Feb 08 '13 at 15:27