Javascript Loop particular number replace

Javascript Loop particular number replace

Hi,

Today We Discuss JavaScript how to replace particular number we create one loop that loop how to replace particular number to some string.

Javscript Loop particular number replace
JavaScript Loop particular number replace



var a = 100;
var str =[];
var ar = [];
for(var i=1;i<a;i++){
if(i.toString().indexOf('4') != -1){
   ar.push('buzz');
else {
   ar.push(i);
}
}
console.log(ar);  ////Replaced 4 number only Buzz


output

 [1, 2, 3, "buzz", 5, 6, 7, 8, 9, 10, 11, 12, 13, "buzz", 15, 16, 17, 18, 19, 20, 21, 22, 23, "buzz", 25, 26, 27, 28, 29, 30, 31, 32, 33, "buzz", 35, 36, 37, 38, 39, "buzz", "buzz", "buzz", "buzz", "buzz", "buzz", "buzz", "buzz", "buzz", "buzz", 50, 51, 52, 53, "buzz", 55, 56, 57, 58, 59, 60, 61, 62, 63, "buzz", 65, 66, 67, 68, 69, 70, 71, 72, 73, "buzz", 75, 76, 77, 78, 79, 80, 81, 82, 83, "buzz", 85, 86, 87, 88, 89, 90, 91, 92, 93, "buzz", 95, 96, 97, 98, 99]

Javascript Loop particular number replace Dev2Tricks 5 of 5
Javascript Loop particular number replace Hi, Today We Discuss JavaScript how to replace particular number we create one loop that l...

Share this

Related Posts

Previous
Next Post »

1 comments:

comments
7 December 2019 at 23:39 delete

we are best calgary roofing companies & Best roofing contractors calgary. Contact us for transparent quotes. roofing calgary & roofing services calgary Roofing Company in Calgary

Reply
avatar