JavaScript’s String, Number and Arrays

Number:

ParseFloat().

const example1 = “100”;

parseFloat(example1) // to convert string to number

String:

String Length

‘Jhon’.length // to find how many characters in this string

String.charAt

‘hello’.charAt(3) // is a thing that returns the number of strings to that location.

string.replace

‘hello, world’.replace(‘world’, ‘earth’)// to replace the old value to new value.

string.toUpperCase()

‘sahil’.toUpperCase()// to convert all string to upper case.

string.toLowerCase()

‘SAHIL’.toLowerCase()// to convert all string to lower case.

toString()

const stringObj = new String(‘foo’);

console.log(stringObj);
// output

const toStaring = stringObj.toString()// convert object to string

console.log(toStaring);
// output

Array:

pop()

const plants = [‘broccoli’, ‘cauliflower’, ‘cabbage’, ‘kale’, ‘tomato’];

const pop = plants.pop()// to remove last string of array

console.log(pop)

console.log(plants)// output

plants.pop();

console.log(plants);// output

push()

const animals = [‘pigs’, ‘goats’, ‘sheep’];

const count = animals.push(‘cows’);// to add a string after last string of array

console.log(count)// output: 4

console.log(animals)// output

animals.push(‘chickens’, ‘cats’, ‘dogs’);// to add a string after last string of array

console.log(animals)// output

slice()

const animals = [‘ant’, ‘bison’, ‘camel’, ‘duck’, ‘elephant’];

const slice =animals.slice(2)// get the first two string

console.log(slice);

console.log(animals)// expected output

animals.push(‘chickens’, ‘cats’, ‘dogs’);

console.log(animals)// expected output