Searches an array for a specified element and returns its position.
var fruits = [“Apple”, “Orange”, “Apple”, “Mango”]; var a = fruits.indexOf(“Apple”); |
lastIndexOf() functions similarly to indexOf(), but it searches the array from the end towards the beginning.
var fruits = [“Apple”, “Orange”, “Apple”, “Mango”]; var a = fruits.lastIndexOf(“Apple”); |
A common use of JSON is to receive data from a web server.
For example, imagine receiving the following text string from a web server:
‘{“name”:”John”, “age”:30, “city”:”New York”}’ |
The JavaScript function JSON.parse() is used to parse the text and convert it into a JavaScript object.
var obj = JSON.parse(‘{“name”:”John”, “age”:30, “city”:”New York”}’); |