JQuery 为什么我的 array.every 不是函数?
JQuery Why my array.every is not a function?
我想知道为什么我的 array.every 不是函数,我搜索了几个小时,但我不明白为什么不是。有人可以帮助我吗?
function controlUserInput(inputText, appLang) {
const regex = /$[^$]*$/gm;
const str = $('#formulaire-preview-textarea').val();
let m;
var array = populateVariable(appLang);
while ((m = regex.exec(str)) !== null) {
// This is necessary to avoid infinite loops with zero-width matches
if (m.index === regex.lastIndex) {
regex.lastIndex++;
}
// The result can be accessed through the `m`-variable.
m.forEach((match, groupIndex) => {
console.log(`Found match, group ${groupIndex}: ${match}`);
var isEqual = match.length==array.length;
for (i=0; i<=array.length-1;i++){
if(displayCpt == 4 && isEqual && match.toArray().every(function(paramInMatch){
return $.inArray(paramInMatch, array) != -1;
})){
osapi.jive.core.container.sendNotification({
"message": "Toutes les valeurs rentrées sont correctes",
"severity": "success"
});
}else{
osapi.jive.core.container.sendNotification({
"message": "Vous n'avez pas utilisé toutes les valeurs",
"severity": "error"
});
}
}
})
};
}
.toArray()
是一个 jQuery 对象方法,因为你的 match
不是 jQuery 对象,它不会工作。
你可以使用普通的 javascript Array.from(match)
.
我想知道为什么我的 array.every 不是函数,我搜索了几个小时,但我不明白为什么不是。有人可以帮助我吗?
function controlUserInput(inputText, appLang) {
const regex = /$[^$]*$/gm;
const str = $('#formulaire-preview-textarea').val();
let m;
var array = populateVariable(appLang);
while ((m = regex.exec(str)) !== null) {
// This is necessary to avoid infinite loops with zero-width matches
if (m.index === regex.lastIndex) {
regex.lastIndex++;
}
// The result can be accessed through the `m`-variable.
m.forEach((match, groupIndex) => {
console.log(`Found match, group ${groupIndex}: ${match}`);
var isEqual = match.length==array.length;
for (i=0; i<=array.length-1;i++){
if(displayCpt == 4 && isEqual && match.toArray().every(function(paramInMatch){
return $.inArray(paramInMatch, array) != -1;
})){
osapi.jive.core.container.sendNotification({
"message": "Toutes les valeurs rentrées sont correctes",
"severity": "success"
});
}else{
osapi.jive.core.container.sendNotification({
"message": "Vous n'avez pas utilisé toutes les valeurs",
"severity": "error"
});
}
}
})
};
}
.toArray()
是一个 jQuery 对象方法,因为你的 match
不是 jQuery 对象,它不会工作。
你可以使用普通的 javascript Array.from(match)
.