Number is a primitive wrapper object used to represent.
The number constructor contains constants and methods for working with numbers. Values of other types can be converted to numbers using the number () function.
parseInt(): ParseInt is a built-in function. It’s convert a string to an integer.
parseInt('111'); // 111
parseInt('090'); // 90
NaN: NaN is short of “not a number”. It’s returned if the string is non-numeric.
parseInt('Fatiha', 10); // NaN
The string object is used to represent and manipulate a sequence of characters. String can be created as primitives, from string literals, or as objects, using the String() constructor.
const string primitive = "Fatiha";
const string primitive = 'Fatiha';
const string primitive = `Fatiha`;const string primitive = new String("Fatiha");
There are two ways to access an individual character in a string. The first is the charAt() method and the second is an array like object;
return 'fatiha'.charAt(3) // returns "i"
return 'fatiha' // returns "t"
Split: The split() method divides a string into an ordered list of substrings, puts these substrings into an array, and returns the array. The division is done by searching for a pattern; where the pattern is provided as the first parameter in the method's call.
const str = ‘The quick brown fox jumps over the lazy dog.’;
const str = ‘no pain no gain.’;
const words = str.split(‘ ‘);
// expected output: 'gain'
map(): The map() method creates a new array populated with the results of calling a provided function on every element in the calling array.
const array1 = [1, 4, 9, 16];// pass a function to map
const map1 = array1.map(x => x * 2);console.log(map1);
// expected output: Array [2, 8, 18, 32]
concat(): The concat() method is used to merge two or more arrays. This method does not change the existing arrays, but instead returns a new array.
const array1 = ['a', 'b', 'c'];
const array2 = ['d', 'e', 'f'];
const array3 = array1.concat(array2);console.log(array3);
// expected output: Array ["a", "b", "c", "d", "e", "f"]
pop(): The pop()method removes the last element from an array and returns that element. This method changes the length of the array.
const plants = ['Rahim', 'karim', 'jadu', 'mudhu', 'kuddus'];console.log(plants.pop());
// expected output: "kuddus"
// expected output: Array['Rahim', 'karim', 'jadu', 'mudhu'];