Replace Spaces With Underscores In An Array Javascript

[Solved] Replace Spaces With Underscores In An Array Javascript | Php - Code Explorer | yomemimo.com
Question : javascript replace space by underscore

Answered by : vastemonde

// replaces space with '_'
str = str.replace(/ /g, "_");
// or
str = str.split(' ').join('_');

Source : | Last Update : Tue, 18 May 21

Question : replace spaces with underscores in an array javascript

Answered by : richard-lievesley

var my_array = ['text one', 'text two', 'text three']
console.log(my_array) // Prints normally.
my_array = spacesToUnderscores(my_array)
console.log(my_array) // Now all strings have underscores instead of spaces.
function spacesToUnderscores(arr)
{ for(let i=0; i<=arr.length-1; i++) arr[i] = arr[i].replace(' ', '_') return arr
}

Source : | Last Update : Wed, 28 Sep 22

Answers related to replace spaces with underscores in an array javascript

Code Explorer Popular Question For Php