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 »

3 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
5 April 2020 at 16:30 delete

Mr Sanjay Baghela focus to reflects as the best leader of SEO in the world, and his dedication and expertise in SEO field make him enable as the owner of the best BEST SEO Expert India. You can connect with him anytime and you can see his knowledge about SEO itself. Drop your request and dial his number now!
best seo expert in india

Reply
avatar
6 April 2020 at 10:05 delete

With Sanjay Baghela, your business Website is in safe hands. He and his team are the best SEO Expert in India the leading digital marketing field.
Best SEO Expert In India
Best Seo Company in India

Reply
avatar