簡體   English   中英

在Angular-JS中獲取數組大小

[英]Get Array size in Angular-JS

我試圖獲得一個數組的大小,但是每次控制台說我未定義並且不知道為什么時。

.success(function (data) {
            console.log('Random-Suffix:' + suffix);
            $scope.builds = new X2JS().xml_str2json(data);

            var size  = $scope.builds.length;
            console.log('Size: ' + size);



            $timeout(function () {
                $scope.exampleLiveDataChange();
            }, 3000);
        })

根據我在X2JS文檔中閱讀的內容

<instance>.xml_str2json - Convert XML specified as string to JSON

也許構建不是數組,而是對象。 如果對象包含這樣的數組:

var test = {one : 'one' , two : [1,2,3]};

如果您這樣做:

test.length;

你得到:

undefined

如果您這樣做:

test.two.length;

然后您得到:

3

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM