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".

3
  • 1
    You probably want array[5][1]. array[[5]] is the same as array[5] by coincidence, but array[[5[1]]] is just wrong. Commented Feb 8, 2013 at 15:15
  • array[[5]] and array[[5[1]]] don't make sense. Commented Feb 8, 2013 at 15:15
  • possible duplicate of I have a nested data structure / JSON, how can I access a specific value? Commented Feb 8, 2013 at 15:17

2 Answers 2

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.

Sign up to request clarification or add additional context in comments.

Comments

0

Use the split() method of javascript

var part = array[[5]];
var arr = part.split(',')
console.log(arr[1]);

2 Comments

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().
@PaulS. may be you are right, but in his question he said, he reached in following console.log(array[[5]]); to get response ["<a href="twi...ontrolled through diet.", "145339"]..........

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.