1 . Write a Program to reverse a string in JavaScript
const kk = 'kishan'
console.log(kk.split('').reverse().join(''))
2.Write a Program to check whether a string is a palindrome string.
ANS: home work
- find the largest number in array
const array = [30,100.3000,34,99999,10]
function kk(array){
let largest = array[0]
for(let i = 0 ; i< array.length ; i ++){
if(array[i]<largest){
largest = array[i];
}
}
console.log(largest)
}
kk(array)
- how to empty array in javascript
=> array.length = 0
console.log(array);
Using while with pop()
const array = [30, 100, 3000, 34, 99999, 10];
while (array.length > 0) {
array.pop();
}
console.log(array); // Output: []
3. Using splice()
const array = [30, 100, 3000, 34, 99999, 10];
array.splice(0, array.length);
console.log(array); // Output: []
Using a for loop:
const array = [30, 100, 3000, 34, 99999, 10];
for (let i = array.length - 1; i >= 0; i--) {
array.pop();
}
console.log(array); // Output: []
5 how would you check if a number is a interger
her i have 2 way
first id inbuilt function i.e Number.isInteger(12)
second way
if(number% 1 === 0 ){
console.log(true )
}else{
console.log(false )
}
Top comments (0)