从对象的内容中获取值

get values from contents of an object

本文关键字:获取 对象      更新时间:2023-09-26

我有这个库howler.min.js,我用它把mp3分成4部分。这是我创建声音变量的代码:

var sound = new Howl({
  urls: ['singasong.mp3'],
  sprite: { //function
    w0: [360, 290], //[begining,duration in milliseconds]
    w1: [650, 450],
    w2: [1110, 280],
    w3: [1270, 330],
    w4: [1600, 210]
  }
});

我想获得括号内的第二个值(290450280330210),并获得一个数组。我试过这两种方法:

a = $.makeArray(sound.sprite.arguments); // One way to do it
a = sound.sprite.arguments.toArray();  // The other way

但没有奏效。

有人能帮我吗?提前感谢!

您需要迭代sprite对象的键,并在索引1:处推送数组值

var values = [];
for (var key in sound.sprite) {
    values.push(sound.sprite[key][1]);
}