JSFiddle - React, Tailwind, and code Playground

by deepak sisodiya

JavaScript

// Javascript array method

var alert  = function (str) {
   var st = document.createTextNode(str);
   var p = document.createElement('p');
   p.appendChild(st);
   document.querySelector('body').appendChild(p);
}

// concat()
var alpha = ["a", "b", "c"];
var numeric = [1, 2, 3];
var alphaNumeric = alpha.concat(numeric);
alert(alphaNumeric)

/* Javascript array filter() method creates a new array with all elements that pass the test implemented by the provided function */
function isBigEnough(element, index, array) {
  return (element >= 10);
}
var filtered  = [12, 5, 8, 130, 44].filter(isBigEnough);
alert(filtered)

/*Javascript array indexOf() method returns the first index at which a given element can be found in the array, or -1 if it is not present*/
var index = [12, 5, 8, 130, 44].indexOf(8);
alert(index)
var index = [12, 5, 8, 130, 44].indexOf(13);
alert(index)

/* Javascript array join() method joins all elements of an array into a string. */
var arr = new Array("First","Second","Third");
var str = arr.join();
alert(str)

/* Javascript array pop() method removes the last element from an array and returns that element. */
var number = [1,2,3,4]
var element = number.pop()
alert(element)
alert(number)

/* Javascript array push() method appends the given element(s) in the last of the array and returns the length of the new array. */
var element = number.push(2)
alert(element)
alert(number)

// Javascript array reverse() method reverses the element of an array. 
var reverse = number.reverse()
alert(reverse)

// Javascript array sort() method sorts the elements of an array.
var sort = number.sort()
alert(sort)