对象数组

以下是为您整理出来关于【对象数组】合集内容,如果觉得还不错,请帮忙转发推荐。

【对象数组】技术教程文章

Javascript:如何使用已排序的唯一数组将对象数组转换为对象?【代码】

有这种结构的数据:$input = [ { animal: 'cat', name: 'Rocky', value: 1 },{ animal: 'cat', name: 'Spot', value: 2 },{ animal: 'dog', name: 'Spot', value: 3 } ];需要尽可能快的方法来转换为这种格式:$output = { animal: [ 'cat', 'dog' ],name: [ 'Rocky', 'Spot' ],value: [ 1, 2, 3 ] };输出应具有与输入中每个对象中的每个键相等的键.并且输出值应该是具有已排序的唯一值的数组.我发现了一些使用嵌套循环的方法,但比...

javascript – 从对象数组中的属性创建对象【代码】

我有一个这样的对象数组:[ {id: 'id1', random: 'labels.prop1'}, {id: 'id2', random: 'labels.prop2'}, {id: 'id3', random: 'texts.anotherprop'} ]是否有一种简短的方法从该数组生成一个基于属性随机的对象?我需要这个:{texts: { anotherprop: ''},labels: { prop1: '', prop2: '' } }解决方法:您可以使用reduce()两次来构建此嵌套对象.var data = [ {id: 'id1', random: 'labels.prop1'}, {id: 'id2', random: 'labels.pro...

在另一个键上调整对象数组而不会干扰JavaScript中的先前排序(部分排序)【代码】

我有一个这样的对象数组:var booksArray = [ {Id:1,Rate:5,Price:200,Name:"History"},{Id:2,Rate:5,Price:150,Name:"Geographic"},{Id:3,Rate:1,Price:75,Name:"Maths"},{Id:4,Rate:2,Price:50,Name:"Statistics"},{Id:5,Rate:3,Price:120,Name:"Drawing"},{Id:6,Rate:2,Price:100,Name:"Arts"},{Id:7,Rate:3,Price:110,Name:"Chemistry"},{Id:8,Rate:4,Price:160,Name:"Biology"},{Id:9,Rate:4,Price:90,Name:"Software Engine...

c# – 返回对象数组的不同列表,其中数组项的数量是非特定的【代码】

有没有办法使用LINQ从对象数组列表中获取不同的项目列表,而不知道每个数组中有多少项?每个数组项中的项数在整个列表中都是相同的.// Foo is a list of object arrays. The number of items// each array is non-specific.// (In this example there is only 3 items, but there could be 100)var foo = new List<object[]>();// I add some items to the list.foo.Add(new object[] { 1, "Something", true });foo.Add(new object...

java – 如何在Android中使用For循环创建对象数组【代码】

我正在尝试使用Android中的for循环创建一个对象数组.该数组包含一个从数据库中获取的字符串和一个图像(为了方便起见,我将图像保持在同一个图像中). 我从以下开始(这确实有效):ItemData[] itemsData = {new ItemData(dbString[0], R.mipmap.ic_launcher),new ItemData(dbString[1], R.mipmap.ic_launcher),new ItemData(dbString[2], R.mipmap.ic_launcher),new ItemData(dbString[3], R.mipmap.ic_launcher),new ItemData(dbStrin...

javascript – 根据键和基于值对对象数组进行排序【代码】

考虑一下:[{name:'John'},{age:25},{address:'some street'}]正如您所看到的,没有一个键是一致的名称,因此我无法使用.arr.sort((a,b)=> a.consistentKey < b.consistentKey);我怎样才能按名称和价值来排序这样的东西呢? 所以按字母顺序按键排序的应该是:[{address:'some street'},{age:25},{name:'John'}]解决方法:如果您正在考虑首先根据键进行排序,然后再根据值进行排序,则可以尝试以下操作:var a = [{name:'John'},{age:25}...

javascript – 使用lodash将对象数组分组为特定格式【代码】

我有这个对象数组,我需要修改它以使渲染更容易.我使用了类似问题中提到的一些代码:Group array of object nesting some of the keys with specific names 这是我的数组和代码function groupAndMap(events, Year, Month, predic){return _.map(_.groupBy(events,Year), (obj,key) => ({[Year]: key,[Month]: (predic && predic(obj)) || obj})); }const items = [ { "Year": 2018,"Month": 7,"Day": 2,"Title": "event1","StartDat...

javascript – 使用另一个对象数组过滤对象数组【代码】

这个问题类似于这一个Jquery filter array of object with loop,但这次我需要使用一组对象进行过滤. 例: 我有一个这样的对象数组:myArray = [ {userid: "100", projectid: "10",rowid: "0" }, {userid: "101", projectid: "11",rowid: "1"}, { userid: "102", projectid: "12",rowid: "2"}, { userid: "103", projectid: "13",rowid: "3" }, { userid: "101", projectid: "10",rowid: "4" } ...]我想用这样的数组过滤它...

在Java中解析JSON对象数组【代码】

我正在尝试解析以下JSON:{"city":{"id":2643743,"name":"London","coord":{"lon":-0.12574,"lat":51.50853},"country":"GB","population":0},"cod":"200","message":0.0456,"cnt":7,"list":[{"dt":1440504000,"temp":{"day":16.85,"min":14.23,"max":16.85,"night":14.23,"eve":16.32,"morn":16.85},"pressure":1013.06,"humidity":79,"weather":[{"id":500,"main":"Rain","description":"light rain","icon":"10d"}],"speed":7.3...

无法使用javascript对window.opener中的对象数组进行排序【代码】

从我的第一个窗口(我将其称为窗口1)我正在打开第二个窗口(窗口2)使用var w = window.open("", "");在窗口2中,我使用类似的代码引用和操作窗口1中定义的数组window.opener.object2[0].drivedistance = driveDistance;这段代码工作正常.但是,在窗口2中显示此数组的结果之前,我需要对其进行排序.我尝试排序:window.opener.objects2.sort(compareFunc)function compareFunc(a, b){ return (a.drivedistance - b.drivedistance)}如果我...