const name1 = "Jack";
const name2 = "Sarah";
const name3 = "Philip";
...
...
...
const name100 = "Amy";const routine = ['eat', 'sleep'];
console.log(routine);Output
[ 'eat', 'sleep' ]
const numbers = [2, 3, 5, 7];
console.log(numbers);Output
[ 2, 3, 5, 7 ]
const arr = ['eat', 'sleep', 3, 5, 'run'];
console.log(arr);Output
[ 'eat', 'sleep', 3, 5, 'run' ]
const myArray = ['h', 'e', 'l', 'l', 'o'];
console.log(myArray[0]);Output
h
const myArray = ['h', 'e', 'l', 'l', 'o'];
console.log(myArray[0]);
console.log(myArray[1]);
console.log(myArray[2]);Output
h
e
l
const routine = [ 'eat', 'sleep'];
console.log(routine.length);Output
2
let routine = ['eat', 'sleep'];
// add an element at the end
routine.push('exercise');
console.log(routine);Output
['eat', 'sleep', 'exercise']
let routine = ['eat', 'sleep'];
routine[1] = 'exercise';
console.log(routine);Output
[ 'eat', 'exercise' ]
let routine = ['work', 'eat', 'sleep', 'exercise'];
// remove the last element
routine.pop();
console.log(routine);Output
['work', 'eat', 'sleep']
Create an array named greet with values 'hello', 'hi'. Find the length of an array. Add the new element 'welcome' to the array. Find the new length of an array.
const greet = ['hello', 'hi'];
const greetLength = greet.length;
console.log(greetLength);
greet.push('welcome');
const addGreetLength = greet.length;
console.log(addGreetLength);Output
2
3
Q. What is the output of the program?
let routine = [ 'eat', 'sleep'];
routine.push('exercise');
routine[4] = 'work';
console.log(routine[3]);- Error
- exercise
- undefined
- work
Answer: 3