Angular 2 - 检查属性是否为数组

标签 angular

<分区>

在 Angular 2 中,我如何检查属性是否为数组?

我试过构造函数但得到如下函数:

function Array() { [native 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');
}

最佳答案

if(content.value instanceof Array){

另见 Test for array of string type in TypeScript

关于Angular 2 - 检查属性是否为数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41218966/

相关文章:

Angular 2 : Testing components with router

Angular 4从单独的组件重新加载 header 组件

javascript - Webpack 提取 SASS SCSS 到 js 或 json 文件

javascript - 警报不是功能错误是控制台

angular - rxjs/订阅没有导出成员 'ISubscription'

javascript - 具有延迟加载模块的 Angular 5 路由器无法正常工作

angular - 发布请求有效但 Put 请求不在 Angular 2

Angular 2 - 如何从父级触发子级的方法

javascript - 环回验证邮件 http ://https://example. api.com:port

angular - Rxjs同步?