{ geometries: (5) [{…}, {…}, {…}, {…}, {…}] images: (20) [{…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}] materials: (21) [{…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}] textures: (20) [{…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {...} }将以上对象中每个属性的值五等分放在a1-a5的对象中
时间: 2023-07-24 13:44:30 浏览: 59
好的,以下是将每个属性的值五等分放到a1-a5的对象中的代码:
```javascript
const newObj = {
a1: {},
a2: {},
a3: {},
a4: {},
a5: {}
};
// 将 geometries 属性的值五等分放到 newObj 的 a1-a5 属性中
const geoLength = object.geometries.length;
for (let i = 0; i < geoLength; i++) {
const index = Math.floor(i / (geoLength / 5));
newObj[`a${index+1}`].geometries = object.geometries.slice(index*(geoLength/5), (index+1)*(geoLength/5));
}
// 将 images 属性的值五等分放到 newObj 的 a1-a5 属性中
const imgLength = object.images.length;
for (let i = 0; i < imgLength; i++) {
const index = Math.floor(i / (imgLength / 5));
newObj[`a${index+1}`].images = object.images.slice(index*(imgLength/5), (index+1)*(imgLength/5));
}
// 将 materials 属性的值五等分放到 newObj 的 a1-a5 属性中
const matLength = object.materials.length;
for (let i = 0; i < matLength; i++) {
const index = Math.floor(i / (matLength / 5));
newObj[`a${index+1}`].materials = object.materials.slice(index*(matLength/5), (index+1)*(matLength/5));
}
// 将 textures 属性的值五等分放到 newObj 的 a1-a5 属性中
const texLength = object.textures.length;
for (let i = 0; i < texLength; i++) {
const index = Math.floor(i / (texLength / 5));
newObj[`a${index+1}`].textures = object.textures.slice(index*(texLength/5), (index+1)*(texLength/5));
}
console.log(newObj);
```
注意:为了方便,我将新的对象属性名设置为了 a1-a5。如果您有其他要求,可以随时告诉我。
阅读全文