Ajouter du texte à des valeurs
Bonjour,
J'ai un objet, et je voudrais ajouter le même texte aux valeurs de cet objet:
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
|
var arr = {
'username': ['hello1', 'hello2'],
'password': ['hola1']
}
var str = 'hi';
var news = [];
$.each(arr, function(ind, val){
for (var i = 0; i <= val.length-1; i++){
var rep = val[i].replace(val[i], str+' '+val[i]);
news.push(rep);
}
});
console.log(news);
/* Resultat
["hi hello1", "hi hello2", "hi hola1"]
0
:
"hi hello1"
1
:
"hi hello2"
2
:
"hi hola1"
*/ |
Alors que je cherche le même objet avec le texte ajouté:
Code:
1 2 3 4 5
|
var arr = {
'username': ['hi hello1', 'hi hello2'],
'password': ['hi hola1']
} |
Merci à vous