2017-04-14 69 views
-1

所以我有一些函數,它返回新的Object()裏面的數據。如何從返回的對象中獲取數據?

事情是這樣的:

function foo() { 
    ... 
    let arr = ['one', 'two', 'three']; 
    return new Bar(arr); 
} 

的console.log表明這一點:

Bar { 'one', 'two', 'three' } 

我怎樣才能把他們救出來? 例如,設置可變首先看重>「一」

更新:這裏就是我想:https://github.com/sindresorhus/get-urls

+2

它取決於'Bar'類提供的API。 – Barmar

+1

你對Bar的定義在哪裏? –

+0

很難相信這就是你在控制檯看到的結果 – charlietfl

回答

0

可以使用Array.from()功能

實例轉換SetArray

function foo() { 
 
    let arr = ['one', 'two', 'three']; 
 
    return new Set(arr); 
 
} 
 

 
let results = Array.from(foo()); 
 

 
console.log(results);// print the array 
 

 
let value1 = results[0]; // one 
 
let value2 = results[1]; // two 
 
let value3 = results[2]; // three 
 

 
console.log(value1, value2, value3);

之後,你可以使用數組做任何你想要的。

0

應該定義存儲這些值和一些訪問方法來檢索它們的構造函數。