我有一个字符串,例如:
"The red letters in the following words are suffixes: beauti*ful*, speech*less* and invinc*ible*."
Run Code Online (Sandbox Code Playgroud)
我想**用<span class='red'>第二个替换第一个和第二个</span>.我可以在for循环中执行此操作,但想知道如何使用RegExp执行此操作.
我有一个现有的对象文字:
var words=[
{
"word":"callous",
"definition":"uncaring",
"examples": [
{"sentence":"How could you be so callous?"},
{"sentence":"What a callous thing to say!"},
{"sentence":"That showed a callous disregard for the consequences."}
]
}
Run Code Online (Sandbox Code Playgroud)
];
我正在尝试动态添加更多对象,如下所示:
var obj={};
obj.word="nextword";
obj.definition ="nextword definition";
obj.examples= ???;
for (var i = 0; i < nextwordSentencesArray.length; i++) {
??? obj.examples.sentence.push(nextwordSentencesArray[i]);
}
words.push(obj);
Run Code Online (Sandbox Code Playgroud)
我曾在-???-尝试过各种选项,但没有任何效果。感激之至。