Curriculum
Course: JavaScript Basic
Login

Curriculum

JavaScript Basic

JSHome

0/216
Text lesson

Array indexOf()

Searches an array for a specified element and returns its position.

Example

var fruits = [“Apple”“Orange”“Apple”“Mango”];
var a = fruits.indexOf(“Apple”);

Array lastIndexOf()

lastIndexOf() functions similarly to indexOf(), but it searches the array from the end towards the beginning.

Example

var fruits = [“Apple”“Orange”“Apple”“Mango”];
var a = fruits.lastIndexOf(“Apple”);

JSON.parse()

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”}’);