我有一个现有对象,我想将一个新对象推入其中,但没有要定位的属性
例如:
existingObj = { data: {postion: 1 } };
objToPush = { person: [{ name: "Bella", age: 100}], about: { height: "1.70", weight: "170"} }
end up with existingObj = { data: {postion: 1 }, person: [{ name: "Bella", age: 100}], about: { height: "1.70", weight: "170"} }
Run Code Online (Sandbox Code Playgroud)
所以我想添加objTopush到existingObj,但没有目标属性existingObj
虽然我知道 JS 中的 promise,但返回单个对象。这只是我在我的 chrome 检查器上玩弄它并想知道为什么它只会返回已解析的值(需要解释)
const soccerPlayer = ["Messi", "Maradona", "Lebron", "Mane"];
const myPromise = new Promise(( resolve, reject) => {
soccerPlayer.forEach( element => {
if( element.startsWith("M")) {
resolve("Thats a soccer star");
} else {
reject("Not a soccer star");
}
})
});
myPromise
.then(res => console.log(res));
.catch(err => console.log(err));
Run Code Online (Sandbox Code Playgroud)
这只会打印“Thats a Football star”,尽管“Lebron”不以 m 开头,应该被拒绝
我有一个v-text-fieldin vue,我想删除所有空白或防止其中出现任何空白。例如'Project Number'输入应该是'ProjectNumber'.
我有一个功能,但这不起作用,我也尝试过 keyup。
<v-text-field
@input='removeWhiteSpace(row.newCol)'
outlined
dense
color="primary"
style="width: 200px;"
v-model="row.newCol">
</v-text-field>
removeWhiteSpace(text) {
return text.replace(/[\s\/]/g, '');
}
Run Code Online (Sandbox Code Playgroud) 我有这个结果我的api调用的JSON数据,但是当我尝试访问属性"69106658_5"中的数据时,我无法得到"错误:未捕获的SyntaxError:无效或意外的令牌".我有一份我在下面的在线编辑器上运行的内容.我猜它是因为属性包含下划线.
let results=
{
"links": {
"data": {
"self": {
"body": "",
"content_type": "",
"href": "/api/v2/nodes/69107289/categories",
"method": "GET",
"name": ""
}
}
},
"results": [
{
"data": {
"categories": {
"58652374_10": [
"16",
"16.0.1",
"16.2",
"16.2.4"
],
"58652374_11": [
"English"
],
"58652374_12": [
"Windows"
],
"58652374_13": "2018-11-20T00:00:00",
"58652374_2": "Published",
"58652374_3": "19",
"58652374_4": "Video",
"58652374_5": "65",
"58652374_6": "How To",
"58652374_7": [
"basic"
],
"58652374_8": "237",
"58652374_9": "Content Server"
}
}
},
{
"data": {
"categories": {
"69106658_2": "You Tube",
"69106658_3": [ …Run Code Online (Sandbox Code Playgroud)javascript ×4
arrays ×1
es6-promise ×1
json ×1
object ×1
postman ×1
promise ×1
vue.js ×1
vuetify.js ×1