string.push javascript code example

Example 1: nodejs add element to array

var array = [];
array.push(element)
console.log(array);

Example 2: array.push

var vegetables = ['Capsicum',' Carrot','Cucumber','Onion'];
vegetables.push('Okra');
//expected output ['Capsicum',' Carrot','Cucumber','Onion','Okra']; 
// .push adds a thing at the last of an array

Example 3: js concatenate strings

const str1 = 'Hello';
const str2 = 'World';

console.log(str1 + str2);
>> HelloWorld

console.log(str1 + ' ' + str2);
>> Hello World

Example 4: string concatenation js

var aString="";
aString.concat(value1, value2, ... value_n);