javascript - 函数无法识别来自另一个函数的条件
问题描述
我有这个功能:
function checkDuplicity(){
for (var i = 0; i < newCombination.length; i++) {
if(JSON.stringify(newCombination[i]) == localStorage.getItem("test")){
return false
}
}
return true
}
当我在 DevTools 中检查此函数时,它会在满足或不满足条件时返回正确的布尔值。
我在这里使用这个函数作为执行函数的条件。
function makeId(){
if(storedDate != null){
if (checkDuplicity()) {
localStorage.setItem("combination"+(localStorage.length+1), JSON.stringify({
movie: storedMovie,
date: storedDate,
time: storedTime
}));
}
}}
即使我在 DevTools 中检查了 checkDuplicity() 的输出并且它的错误 - 上面的函数仍然被执行。
谢谢
这是 newCombination 的填充方式:
var newCombination = []
function pushingInForm() {
for (var i = 1; i <= localStorage.length; i++) {
if ((localStorage.getItem('combination' + i) != null)) {
var push = JSON.parse(localStorage.getItem("combination" + i));
newCombination.push(push);
} else {
//
}
解决方案
推荐阅读
- iframe - 拉诺雷克斯。iframe 访问问题
- python - 将月份列数据转换为行
- android - Gradle,Gradle 包装器在 Android Studio 中由 ionic cordova 的不同实例
- objective-c - 将 Swift 类从 react-native-library 导入到用 Objective-C 编写的示例应用程序中
- python - 读取 CSV 文件时发生回溯错误
- splunk - Splunk 输入查找和结果提取
- excel - 粘贴后自动替换列中的文本
- wpf - WPF 等效于 jQuery 的类选择器
- django - 依赖登录的Django缓存和页面部分
- laravel - 未找到 Laravel 类 'Illuminate\Support\Facades\Http'