【发布时间】:2020-01-21 20:11:47
【问题描述】:
以下是我在 json 响应中得到的一些 obj 数组的示例:
0: {day: "7", starting_time: "0800", closing_time: "1600"}
1: {day: "1", starting_time: "0600", closing_time: "1600"}
2: {day: "2", starting_time: "0600", closing_time: "1600"}
3:
closing_time: "1600"
day: "3"
starting_time: "0600"
__proto__: Object
我通过以下方式获得当前星期几的值:
var d = new Date();
var dayOfWeek = d.getDay();
var hour = d.getHours();
我只是想使用我得到的dayOfWeek 值(即今天它是5)-并使用它从我的json 中获取数组obj 5: 来获取它(this ) json 响应的工作天数。
以下是我最近尝试过的。
function matchingDay(hoursoperations) {
return hoursoperations === dayOfWeek;
}
console.log(myJson.bla.findIndex(matchingDay));
但我收到错误:
index.js:45 Uncaught (in promise) TypeError: myJson.bla.findIndex not a function
更多上下文,数据来自 fetch API。
document.addEventListener('DOMContentLoaded', () => {
loadSVGs();
fetch('https://www.website.com/obfuscate-json/obfuscate/v3/options/obfuscate')
.then(function(response) {
return response.json();
})
.then(function(myJson) {
// .... code ...
【问题讨论】:
-
方法 xxxx 在哪里 promise?你能用小提琴复制这个吗?
-
我已经添加了该信息并对其进行了模糊处理
-
好吧,myJson 似乎不是一个数组,而是一个对象
-
它是一个对象数组
标签: javascript arrays json ecmascript-6 ecmascript-5