I would like to show an object based on a random value of the property "id". The random value has to be between 1 and the amount of objects in the array. Currently I have this:
$(document).ready(function () {
var card = [
{
name: "string 1"
, value: "this"
, other: "that"
, id: 1
}
, {
name: "string 2"
, value: "this"
, other: "that"
, id: 2
}
];
var obj = card.filter(function (obj) {
var length = card.length();
var random = Math.floor(Math.random() * length) + 1
return obj.name === random;
})[0];
console.log(obj);
});