Вопрос по arrays, javascript, jquery – Цикл по массиву и вывод в виде пар (делитель для каждого второго элемента)

7

Error: User Rate Limit Exceeded

$playlist = array();

while (databaseloop) {
  $playlist[] = $a_title;
  $playlist[] = $a_length;
}

echo json_encode(array('playlist'=>$playlist));

Error: User Rate Limit Exceeded

["Hello.mp3", "00:00:14", "Byebye.mp3", "00:00:30", "Whatsup.mp3", "00:00:07", "Goodnight.mp3", "00:00:19"] and so on

Error: User Rate Limit Exceeded

Error: User Rate Limit Exceeded

foreach (two_elements_in_array) {
  // output track name
  // output track time
  // output some divider
}

Error: User Rate Limit Exceeded

Ваш Ответ

9   ответов
0
var arr = ["Hello.mp3", "00:00:14", "Byebye.mp3", "00:00:30", "Whatsup.mp3", "00:00:07", "Goodnight.mp3", "00:00:19"];

var group = [];
for (var x = 0; x < arr.length; x += 2) {
    var track = arr[x],
        length = arr[x + 1];
    group.push({
       track: track,
       length: length
    })
}
0

Error: User Rate Limit Exceeded

for (i = 0; i+1 < array.length; i+=2) {
  name = array[i];
  length = array[i+1];
}
0

foreach.

for (var i = 0; i < array.length; i += 2) {
    var name = array[i];
    var time = array[i + 1];
    // do whatever
}
Error: User Rate Limit ExceededforeachError: User Rate Limit Exceeded
Error: User Rate Limit Exceeded
1

Error: User Rate Limit ExceededError: User Rate Limit Exceeded:

let pairs = playlist.reduce((list, _, index, source) => {
    if (index % 2 === 0) {
        list.push(source.slice(index, index + 2));
    }
    return list;
}, []);

Error: User Rate Limit ExceededpairsError: User Rate Limit Exceeded

0

Error: User Rate Limit Exceeded

var d=["Hello.mp3", "00:00:14", "Byebye.mp3", "00:00:30", "Whatsup.mp3", "00:00:07", "Goodnight.mp3", "00:00:19"] ;
var e=["name","time"];
var c=0;
$.each(d,function(i,j){
    if(c>=2)c=0;
    console.log(e[c]+j);
    c++;
});

Error: User Rate Limit Exceeded

0

Error: User Rate Limit Exceeded

while (arr.length) {
  const Title  = arr.shift();
  const Length = arr.shift();

  // Do work.
}
0

Error: User Rate Limit Exceeded

Error: User Rate Limit Exceeded

var array = [ {name: "Hello.mp3", time: "00:00:14"}, {name: "Byebye.mp3", time:"00:00:30"}, {name: "Whatsup.mp3", time: "00:00:07"}, {name: "Goodnight.mp3", time: "00:00:19"}];

Error: User Rate Limit Exceeded

array.forEach(function(data){
    //edit the output here
    console.log(data.name + " " + data.time );  
});
6

Error: User Rate Limit Exceeded

for (var i = 0; i < arr.length; i += 2) {
    var title = arr[i];
    var len = arr[i+1];
}

Error: User Rate Limit Exceeded$playlistError: User Rate Limit Exceeded

while (databaseloop) {
    $playlist[] = array(
        "title" => $a_title,
        "length" => $a_length
    );
}

Error: User Rate Limit Exceeded

for (var i = 0; i < arr.length; i++) {
    var title = arr[i]['title'];
    var len = arr[i]['length'];
}
Error: User Rate Limit Exceeded mowgli
2

Error: User Rate Limit Exceeded

var arr = ["Hello.mp3", "00:00:14", "Byebye.mp3", "00:00:30", "Whatsup.mp3", "00:00:07", "Goodnight.mp3", "00:00:19"];
arr.map(function(elem,i,arr){return [elem, (i+1<arr.length) ? arr[i+1] : null];})
    .filter(function(elem,i){return !(i%2);});

Похожие вопросы