In Angular 2 how do I check if a property is an array?
I have tried constructor but get a function as below:
function Array() { [native code] }
My Code:
let content: any = {id: '1324234', value:{id:null}};
if(content.value.constructor === 'Array'){
console.log('It is an array');
} else {
console.log('Not an array');
}
To check if an array contains duplicates:Pass the array to the Set constructor and access the size property on the Set . Compare the size of the Set to the array's length. If the Set contains as many values as the array, then the array doesn't contain duplicates.
Duplicate elements can be found using two loops. The outer loop will iterate through the array from 0 to length of the array. The outer loop will select an element. The inner loop will be used to compare the selected element with the rest of the elements of the array.
How do you find duplicate objects in an array? Using the indexOf() method. Using the has() method. Using an object & key value pairs.
if(content.value instanceof Array){
See also Test for array of string type in TypeScript
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With