1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
| const
tab = [];
tab.push( { "pos_id" : "10000", "valeur" : "Lundi" } );
tab.push( { "pos_id" : "10001", "valeur" : "Mercredi" } );
tab.push( { "pos_id" : "10002", "valeur" : "Jeudi" } );
tab.push( { "pos_id" : "10003", "valeur" : "Vendredi" } );
function deleteItemOfTab( key = "Une clé", value = "Une valeur" ){
for ( const [i, item ] of tab.entries() ){
if ( item[ key ] === value ){
tab.splice( i, 1 );
break;
}
}
}
deleteItemOfTab( "pos_id", "10002" );
// debug, console, touche F12
for ( const [i, Obj ] of tab.entries() ){
for ( const key in Obj ){
console.log( i, key, " = ", Obj[ key ] );
}
} |
Partager