JAVASCRIPT代码需要帮助...... [英] Help needed in JAVASCRIPT code ...
问题描述
我似乎无法附加文件,所以我在这里粘贴整个程序:
var dataStore = {
userInformation :{
email:something@gmail.com,
phoneNumber:1234567890,
password: strongpassword,
订单:[{
喘气:{
名称:DFH男士常规健身跑道裤 ,
soldPrice:399,
soldBy:卖方名称,
orderPlacedOn:日期,>
orderNo:#4578940772477,
orderStatus:已交付,
shipTo:{
姓名:MyNamw,
地址:MyCompleteAdress,
PhNo:7894561230
}
}
},
{
book:{
名称:C编程语言,
soldPrice:189,
soldBy:卖方名称,
orderPlacedOn:date,
orderNo:#4578940777477,
orderStatus:已取消,
shipTo:{
姓名:MyName,
地址:MyCompleteAdress,
PhNo:7894561230
}
}
}
],
购物车:[{
mobilePhone:{
name:NewPhone,
Price:7789,
CashOnDelivery:符合条件,
颜色:黄金,
操作系统:Android,
RAM:3 GB,
ItemWeight:172 g,
ProductDimensions:15.2 x 0.8 x 7.5 cm ,
Itemmodelnumber:C103
}
}]
}
}
//函数从JSON文件中读取数据并在控制台中显示。
var readData = function(dataStore)
{
console.log(dataStor e.userInformation.phoneNumber);
}
//使用名称或ID从JSON商店读取特定条目的功能/>
var specificData = function(dataStore)
{
dataStore.userInformation.orders.map(function(item){
console.log(item.pant.orderStatus);
});
}
readData(dataStore);
specificData(dataStore);
i 被要求编写一个函数来查找特定条目通过它的位置/索引(数组中的索引)
在我的程序中,数组是'命令'但我似乎无法从中拉出元素?
需要帮助! !!
我的尝试:
我试过在谷歌搜索但似乎无法找到它!我也经历了w3schools教程,我现在只是敲打我的脑袋!
参见JSON数组 [ ^ ]。
I cant seem to to attach the file so i am pasting my whole program here :
var dataStore = {
"userInformation" : {
"email": "something@gmail.com",
"phoneNumber": 1234567890,
"password": "strongpassword",
"orders": [{
"pant": {
"name": "DFH Men's Regular Fit Track Pant",
"soldPrice": 399,
"soldBy": "SellerName",
"orderPlacedOn": "date",
"orderNo": "#4578940772477",
"orderStatus": "Delivered",
"shipTo": {
"Name": "MyNamw",
"Address": "MyCompleteAdress",
"PhNo": 7894561230
}
}
},
{
"book": {
"name": "The C Programming Language",
"soldPrice": 189,
"soldBy": "SellerName",
"orderPlacedOn": "date",
"orderNo": "#4578940777477",
"orderStatus": "Cancelled",
"shipTo ": {
"Name": "MyName",
"Address": "MyCompleteAdress",
"PhNo": 7894561230
}
}
}
],
"cart": [{
"mobilePhone": {
"name": "NewPhone",
"Price": 7789,
"CashOnDelivery": "Eligible",
"color": "Gold",
"OS": "Android",
"RAM": "3 GB",
"ItemWeight": "172 g",
"ProductDimensions": "15.2 x 0.8 x 7.5 cm",
"Itemmodelnumber": "C103"
}
}]
}
}
//function to Read data from JSON file and display it in console.
var readData = function (dataStore)
{
console.log(dataStore.userInformation.phoneNumber);
}
//Function to read a particular entry from JSON store using a name or id
var particularData = function(dataStore)
{
dataStore.userInformation.orders.map(function(item){
console.log(item.pant.orderStatus);
});
}
readData(dataStore);
particularData(dataStore);
i was asked to write a Function to find a particular entry by its position/index (index in the array)
In my program the array is 'orders' but I cant seem to pull elements out of it?
Help needed !!!
What I have tried:
I have tried to search it in google but cant seem to find it ! Also i went through the w3schools tutorial , I am just banging my head now !
See JSON Arrays[^].
这篇关于JAVASCRIPT代码需要帮助......的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!