如何檢查對象或數組的類型?如何區分對象類型與Typescript中的數組類型
我想添加一個對象(並添加,如果它的對象)某些數組。
//1. should add this OBJECT to the array
var objToAdd11 : Object = {name: 'Zack', age: 24};
this.addObject(objToAdd11);
//2. should throw errorbecause this is ARRAY, and we need only OBJECTS
var objToAdd22 : Array = [{name: 'Zack', age: 24}];
this.addObject(objToAdd22);
public addObject(obj: any) : void {
/*I need to check is obj parameter OBJECT OR ARRAY*/
var myArray : Array = [1, "a", 3];
function() {
myArray.push(obj);
}
var newMyArray : Array = myArray;
}