我想知道如何合并这两个对象以检索标记值并将它们存储在数组中。这些数据也来自json响应,因此应将传入数据推入新数组的末尾。
所以看起来像这样 [“ 2011 LDI”,“ 2012 LDI”]
包含传入数据的数组: [“ 2011 LDI”,“ 2012 LDI”,“ 2013 LDI”]
这是我在console.log中返回的内容:
[19-08-25 21:58:32:055 PDT] []
[19-08-25 21:58:32:056 PDT] []
这是我要合并的两个数组对象:
{date_added=2019-08-26 04:19:00.112083, tag=LDI 2011}
{date_added=2019-08-26 04:19:00.112089, tag=LDI 2012}
我希望它看起来像这样
[LDI 2011,LDI 2012]
以及我的尝试方式。
var tagtest = [];
var tags = message.student_detail.student_tags,
i = 0,
len = tags.length;
for (i; i < len; i++) {
var obj = tags[i];
for (a in obj) {
}
Array.prototype.push(tags, tagtest);
Logger.log(tagtest)
}
答案 0 :(得分:1)
根据所需的输出( try
{
ConfigurationManager<OpenIdConnectConfiguration> configManager = new ConfigurationManager<OpenIdConnectConfiguration>(metaData, new System.Net.Http.HttpClient());
OpenIdConnectConfiguration config = configManager.GetConfigurationAsync().Result;
string tenant = ConfigurationManager.AppSettings["Tenant"];
TokenValidationParameters validationParameters = new TokenValidationParameters
{
ValidateAudience = false,
ValidateIssuer = false,
IssuerSigningKeys = config.SigningKeys, //.net core calls it "IssuerSigningKeys" and "SigningKeys"
ValidateLifetime = false
};
JwtSecurityTokenHandler tokendHandler = new JwtSecurityTokenHandler();
SecurityToken jwt = null;
var result = tokendHandler.ValidateToken(GenUtil.token, validationParameters, out jwt);
Dictionary<string, object> valueColl = ((JwtSecurityToken)jwt).Payload;
if (valueColl["upn"].ToString().Split('@')[0].ToUpper() != GenUtil.user.ToUpper())
{
}
}
catch (Exception ex)
{
}
),您可能只需要数组中的[LDI 2011, LDI 2012]
个值。如果这正是您要寻找的内容,那么tag
将为您提供帮助>
.map()
答案 1 :(得分:0)
for in循环是处理对象的好方法。我更新了上面的代码,以使其实际上是一个对象数组,而不是一个错误。见下文:)
var data = [{date_added: "2019-08-26 04:19:00.112083", tag: "LDI 2011"},
{date_added: "2019-08-26 04:19:00.112089", tag: "LDI 2012"}];
var newArr = [];
for(var item in data) {
newArr.push(data[item].tag);
}
console.log(newArr);