i want to check if an array containes other array in ExtJs i tried this but without success
if( [2,1] in [1,2,3]){
console.log("true"); }
i know that i can do it manualy but is there a direct methode
i want to check if an array containes other array in ExtJs i tried this but without success
if( [2,1] in [1,2,3]){
console.log("true"); }
i know that i can do it manualy but is there a direct methode
var arr1=[2,1],
arr2=[1,2,3];
if(Ext.Array.merge(arr1,arr2).length===arr2.length){
console.log('HELLO!');
}
If you're using Extjs, using this method you can win without functions and cicles
Simply merging the arrays.
You need to loop over the Array to check if the values are in it:
function inArray(v, a){
for(var i=0,l=a.length; i<l; i++){
if(a[i] === v){
return true;
}
}
return false;
}
function allInArray(t, a){
for(var i=0,l=t.length; i<l; i++){
if(!inArray(t[i], a)){
return false;
}
}
return true;
}
var yourArray = [1, 2, 3], tests = [2, 1];
console.log(allInArray(tests, yourArray));
console.log(allInArray([2, 4, 1], yourArray));
// another way
function allIn(t, a){
return t.length === t.map(x => +a.includes(x)).reduce((n, v) => n+v);
}
console.log(allIn(tests, yourArray));
console.log(allIn([3, 4], yourArray));
In extjs you have Ext.each function to loop out through the array
var array_1 = [2,1];
var array_2 = [1,2,3];
Ext.each(array_1,function(value_of_arr1){
if(array_2.indexOf(value_of_arr1) == -1){
console.log('array_1 value doesnt exist');
return;
}else{
console.log('array_1 value does exist');
return;
}
});
In above code the -1 is returned from the if condition if the value of array_1 is not found in the array_2
if value is found the array index in which the value resides is returned