adsterra

Objects with Array in Java Script | with source code

Array object


The Array object lets you store multiple values in a single variable. It stores a fixed-size sequential collection of elements of the same type. An array is used to store a collection of data, but it is often more useful to think of an array as a collection of variables of the same type.

Simple Example:
const myTodo =['Buy bread','go gym''work']
//indexOf() print the index of an element within an array.
 console.log(myTodo.indexOf('Buy bread'));


Creating a simple TODO :
//array with object
const newTodos = [{
    title:'Buy Bread',
    isDone:false,
},{
    title:'go gym',
    isDone:false,
},{
    title:'work',
    isDone:true,
}]
//findindex2
const index=newTodos.find(function (todo) {
    return todo.title==='go gym'
})
console.log(index);

Post a Comment

0 Comments