javascriptで配列をランダムで取得したいのですが、以下のコードで実行すると。
[object, Object]というエラーが出てしまいます。このエラーの意味と対処法を教えていただけると助かります。お願いします。
javascript
1'use strict'; 2 3{ 4 const search = document.getElementById('search'); 5 // const price30 = document.getElementById('price30'); 6 // const price50 = document.getElementById('price50'); 7 // const price75 = document.getElementById('price75'); 8 // const price100 = document.getElementById('price100'); 9 // const style_tb = document.getElementById('style-tb'); 10 // const style_t = document.getElementById('style-t'); 11 // const style_b = document.getElementById('style-b'); 12 const result = document.getElementById('result'); 13 14 search.addEventListener('click', () => { 15 16 const t = [ 17 {name: `UクルーT`, price: 1000}, 18 {name: `ワッフルクルーT`, price: 1500}, 19 {name: `ドライカノコポロシャツ`, price: 1990}, 20 {name: `UオーバーサイズクルーT`, price: 1500}, 21 {name: `UグラフィックT`, price: 1500}, 22 23 ]; 24 25 result.textContent = t[Math.floor(Math.random()*t.length)]; 26 27 // const b = [ 28 // {name: '感動パンツ', price: 3990}, 29 // {name: 'ウルトラストレッチスキニージーンズ', price: 3990}, 30 // {name: 'EZYアンクルパンツ', price: 2990}, 31 // {name: 'チノハーフパンツ', price: 1990}, 32 // ]; 33 34 }) 35}
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2019/05/31 07:54
2019/05/31 08:38
2019/05/31 09:21