gpt4 book ai didi

javascript - 将其他文件中的值对象调用为对象值

转载 作者:行者123 更新时间:2023-12-03 01:07:00 25 4
gpt4 key购买 nike

我的消息对象包含:

const message = {
headers: {
i need to call another object to here
}
};

我在另一个文件中有配置对象:

exports.custom_headers{

'x-my-key': 'header value',
'x-another-key': 'another value'

}

我需要替换 header 的整个名称和值:使用配置文件中的对象

如何引用?我尝试直接调用对象,但没有成功

正常情况下,对象是这样工作的

const message = {
from: random_message.fromname+'<'+random_message.fromemail+'>',
to: email,
subject: random_message.subject,
text: random_message.text,
html: random_message.html,
headers: {
'x-my-key': 'header value',
'x-another-key': 'another value'
}
};

但我需要将 header 导出到另一个文件

最佳答案

如果这就是你想要的。您可以使用...(扩展运算符)来扩展对象的键。

const custom_headers =  {
'x-my-key': 'header value',
'x-another-key': 'another value'
};

const message = {
from: 'random_message.fromname'+'<'+'random_message.fromemail'+'>',
to: 'email',
subject: 'random_message.subject',
text: 'random_message.text',
html: 'random_message.html',
headers:{
...custom_headers
}
};

console.log(message);

关于javascript - 将其他文件中的值对象调用为对象值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52351903/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com