如何使用javascript函数打印键为奇数的数组中的值

如何使用javascript函数打印键为奇数的数组中的值,javascript,Javascript,我是这样做的,但它从一个对象打印出一个随机引号,该对象包含引号作为值,数字索引作为键 displayRandomQuote = function () { var quotes = { 0: "All computers wait at the same speed.", 1: "A good programmer looks both ways before crossing a one-way street.", 2: "Compute

我是这样做的,但它从一个对象打印出一个随机引号,该对象包含引号作为值,数字索引作为键

displayRandomQuote = function () {
    var quotes = {
        0: "All computers wait at the same speed.",
        1: "A good programmer looks both ways before crossing a one-way street.",
        2: "Computers do not solve problems, they execute solutions.",
        3: "The best thing about a boolean is even if you are wrong, you are only off by a bit",
        4: "Ubuntu is an ancient African word, meaning 'can’t configure Debian'",
        5: "Without requirements or design, programming is the art of adding bugs to an empty 'text' file."

    }
    var rand = Math.floor(Math.random() * Object.keys(quotes).length);

    console.log(quotes[rand ]);
}
displayRandomQuote();
displayRandomQuote=函数(){
变量引号={
0:“所有计算机以相同的速度等待。”,
1:“一个好的程序员在过单行道之前要看两边。”,
2:“计算机不解决问题,而是执行解决方案。”,
3:“布尔运算最好的地方是即使你错了,你也只差一点点”,
4:“Ubuntu是一个古老的非洲单词,意思是‘无法配置Debian’,
5:“没有需求或设计,编程就是将bug添加到空‘文本’文件中的艺术。”
}
var rand=(Math.floor(Math.random()*(Object.keys(quotes.length/2))*2)+1;
log(rand+':'+引号[rand]);
}
displayRandomQuote();
//
//或:
//(应使用常规数组)
//
BETTERdisplayRandomQuote=函数(){
变量引号=[
“所有计算机都以相同的速度等待。”,
“一个好的程序员在过单行道之前要看两边。”,
“计算机不会解决问题,而是执行解决方案。”,
“布尔运算最好的地方是即使你错了,你也只差一点点”,
“Ubuntu是一个古老的非洲单词,意思是‘无法配置Debian’”,
“如果没有要求或设计,编程就是将错误添加到空‘文本’文件中的艺术。”
]
var rand=(Math.floor(Math.random()*(quotes.length/2))*2)+1;
log(rand+':'+引号[rand]);
}

更好地显示随机引用()您尝试只过滤奇数键的内容是什么?请发布它,而不是生成一个从0到n的数字,尝试生成一个从0到n/2的数字,然后将其加倍并求和1,确保覆盖所有奇数!注意n是偶数和奇数的情况。为什么不使用正则数组?