Javascript split, splice, join methods

Javascript split, splice, join methods

split(), splice(), join() javascript methods usage:

The split() method splits a String object into an array of strings by separating the string into substrings.

The splice() method changes the content of an array by removing existing elements and/or adding new elements.

The join() method joins all elements of an array into a string.

Code:-

var a = "asdasd|dasd|rttewrtert";

var b = a.split('|'); // ["asdasd", "dasd", "rttewrtert"]

var c = b.splice(1); // ["dasd", "rttewrtert"]

var d=b.join(""); // "asdasddasdrttewrtert";

Code:-

<script>

var isPalindrome = function(x) { return x.toString()=== x.toString().split("").reverse().join(""); };

</script>

var res=isPalindrome(121);

console.log(res);

//Output : true

Hope it helps!