0

Hi i have an array something like below

test = [{"text":"value1","weight":20,"link":"javascript:myink('Val','val')"}]

I want the text value in the above array that is 'value1'. I have tried like this,

var getval= JSON.stringify(test);

But i failed. Please help me

1
  • if you know it's an array, access it like an array; your code is stringifying the entire test array instead of using specifically the first entry in that array, so either you simply forgot to use a [0], which is possible, or you don't quite understand arrays yet, in which case it's a good idea to read up on how to work with arrays in JavaScript Commented Jan 9, 2014 at 9:28

3 Answers 3

3

to read value from that array you would use

var x = test[0].text
Sign up to request clarification or add additional context in comments.

Comments

1

Not sure what you're trying to do with stringify, but to get the value for 'text' in the first element using the array you have declared :

test[0].text

Comments

0
test = [{"text":"value1","weight":20,"link":"javascript:myink('Val','val')"}]

console.log(test[0].text);

There is an array test that has an object at [0] index. This object has several properties one of which is "text". So to access the object we do test[0] and to access the property we do test[0]. That is the complete explanation to your scenario.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.