1-let array = [‘Hello’, ‘world’, ‘!’] -do perform join method with this!!
let array = ['Hello', 'world', '!'];
let joinedString = array.join(' ');
console.log(joinedString); // Output: "Hello world !"
let array= ["Hello", "world", "!"];
let array1= array.join(" ");
console.log(array1);
var x = [“Hello”,“world”, “!”]
var ans =x.join(" ")
console.log(x)
let normal_array= [“Hello”, “world”, “!”];
let joinedArray= normal_array.join(" ");
console.log(joinedArray);
let arrayJoin=array.join(" ");
console.log(arrayJoin);
How do you create an empty array in JavaScript?
let array=[];
console.log(array);
var array=[];
console.log(array);
var x=[];
document.write(x);
let arr = [‘Hello’, ‘world’, ‘!’];
let joinMethod = array.join(‘+’);
document.write(joinMethod); //output: ‘Hello’+ ‘world’+‘!’
Method 1: Using array literal notation
let emptyArray = [];
Method 2: Using the Array()
constructor
let emptyArray = new Array();
How do you add an element to the end of an array?
let arr= [];
document.write(arr);
var x = [“val1”, “val2”, “val3”]
var ans =x.push(“val4”)
console.log(x)
var array=[1,2,3,4,5,6,7,8,9]
var array1=array.push(10);
console.log(array1);
let array_NEW = [];
document.write(array_NEW);
To add an element to the end of an array in JavaScript, we can use the push()
methodThe push()
method to appends one or more elements to the end of an array and returns the new length of the array.
let array = ['apple', 'banana', 'orange'];
console.log(array); // Output: ['apple', 'banana', 'orange']
array.push('mango');
console.log(array); // Output: ['apple', 'banana', 'orange', 'mango']
In the aboev code, the push()
method is called on the array
variable and the element 'mango'
is passed as an argument. The 'mango'
element is added to the end of the array, resulting in ['apple', 'banana', 'orange', 'mango']
.