Just a concise version of Code Maniacs version. ++ to Code Maniac.
const stringSentence = `Hello, my name is --%-- and I am from --%-- and I drink a --%--`;
const arr = ['Jacob', 'New York', 'Juice'];
const replaceString = (str,arr) => str.replace(/--%--/g,()=> arr.shift());
console.log(replaceString(stringSentence, arr))
You can loop through the array of words and use replace()
--%--
with the corresponding word.
let stringSentence = 'Hello, my name is --%-- and I am from --%--';
function replaceString(str, arr){
for(let elm of arr){
str = str.replace('--%--', elm);
}
return str;
}
console.log(replaceString(stringSentence , ['John', 'London']))
I am new to JavaScript and Redux. I am trying to filter an array based on id in one of the reducers in Redux, it does not work if I only pass id to the callback function, but it works if the id is ...
I am new to JavaScript and Redux. I am trying to filter an array based on id in one of the reducers in Redux, it does not work if I only pass id to the callback function, but it works if the id is ...
I have some form fields that are dynamically generated form the database. There are inputs, checkboxes, radio buttons, textarea's, and select's. All the fields are in a parent div with ID dynamic-form-...
I have some form fields that are dynamically generated form the database. There are inputs, checkboxes, radio buttons, textarea's, and select's. All the fields are in a parent div with ID dynamic-form-...
I've read that javascript was in part based on Scheme, a dialect of LISP. When I was reading about this and LISP, it struck me that the javascript function expression syntax seemed like a similar kind ...
I've read that javascript was in part based on Scheme, a dialect of LISP. When I was reading about this and LISP, it struck me that the javascript function expression syntax seemed like a similar kind ...
I am trying to make a Python 3 application to download weather data from my account at http://www.osanywhereweather.com. I have found JavaScript source code that does exactly this at https://github....
I am trying to make a Python 3 application to download weather data from my account at http://www.osanywhereweather.com. I have found JavaScript source code that does exactly this at https://github....