在 javascript 中,我有以下對象:console.log(data)(10) [{…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}]0: {species: "Citronela paniculata", cbh: Array(1)}1: {species: "Myrcia splendens", cbh: Array(1)}2: {species: "Araucaria angustifolia", plot: 1, cbh: Array(1)}3: {species: "Bacharis montana", cbh: Array(1)}4:cbh: (2) [10, 20]plot: 1species: "Casearia decandra"__proto__: Object5: {cbh: Array(1), species: "Bacharis montana"}6: {cbh: Array(3), species: "Ilex paraguariensis"}7: {cbh: Array(1), species: "Ilex paraguariensis"}8: {species: "Ilex paraguariensis", cbh: Array(1)}9: {plot: 1, cbh: Array(1), species: "Araucaria angustifolia"}length: 10__proto__: Array(0)我想將數組 cbh 的每個元素除以 pi,然后我使用:let newData = data.map(({ plot, species, cbh }) => { let dbh = cbh/Math.PI; return { plot, species, cbh, dbh }; })但對于那些具有多個元素的數組,我得到 NaN: console.log(newData)(10) [{…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}]0: {plot: undefined, species: "Citronela paniculata", cbh: Array(1), dbh: 9.549296585513721}1: {plot: undefined, species: "Myrcia splendens", cbh: Array(1), dbh: 10.185916357881302}2: {plot: 1, species: "Araucaria angustifolia", cbh: Array(1), dbh: 5.729577951308232}3: {plot: undefined, species: "Bacharis montana", cbh: Array(1), dbh: 4.7746482927568605}4:cbh: (2) [10, 20]dbh: NaNplot: 1species: "Casearia decandra"__proto__: Object5: {plot: undefined, species: "Bacharis montana", cbh: Array(1), dbh: 6.366197723675814}6: {plot: undefined, species: "Ilex paraguariensis", cbh: Array(3), dbh: NaN}7: {plot: undefined, species: "Ilex paraguariensis", cbh: Array(1), dbh: 6.366197723675814}8: {plot: undefined, species: "Ilex paraguariensis", cbh: Array(1), dbh: 15.915494309189533}9: {plot: 1, species: "Araucaria angustifolia", cbh: Array(1), dbh: 15.915494309189533}length: 10__proto__: Array(0)如何將cbh中的每個元素除以pi?任何提示都會很棒!先感謝您!
不同對象內矩陣的數學運算
BIG陽
2023-08-10 10:51:45