Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Angular 2 - Check if property is an array [duplicate]

Tags:

angular

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');
}
like image 684
Ka Tech Avatar asked Dec 19 '16 09:12

Ka Tech


People also ask

How do you check if an object has duplicate 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.

How do you find duplicates in an array?

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 array typescript?

How do you find duplicate objects in an array? Using the indexOf() method. Using the has() method. Using an object & key value pairs.


1 Answers

if(content.value instanceof Array){

See also Test for array of string type in TypeScript

like image 82
Günter Zöchbauer Avatar answered Sep 23 '22 07:09

Günter Zöchbauer