我有一个包含单个对象的数组,并且该对象内部有一些对象 我想删除第一个对象并将所有对象散布到数组中 我有这个
# Define UI ----------
ui <- fluidPage(
# Sidebar panel
sidebarLayout(
sidebarPanel(
selectInput('addrm',
label = h3('Remove or add words'),
choices = list('Remove words' = 1,
'Add words' = 2)),
textInput('words',
label = 'You can introduce multiple words separated by comma',
placeholder = 'Enter words...'),
uiOutput('button')
),
# Main panel
mainPanel(
textOutput('removeWords')
)
)
)
# Define server logic required ------------
server <- function(input, output){
output$button <- renderUI({
if (input$addrm == 1){
actionButton('button', label = 'Remove words')
} else{
actionButton('button', label = 'Add words')
}
})
stopwords <- c()
output$removeWords <- renderText({
input$button
isolate({ # Only runs when the button is clicked
stopwords <- unique(c(stopwords, unlist(strsplit(gsub(' ', '', input$words), ','))))
})
})
}
# Run the application
shinyApp(ui = ui, server = server)
我想要这个...
friends: [
{
one: {
id: 'one',
address: 'something'
},
two: {
id: 'two',
roomID: 'something'
},
me: 'three'
}
]
答案 0 :(得分:1)
当您想过滤数据以仅获取内部对象时,可以尝试一下
func scrollViewDidScroll(UIScrollView)
其中UIScrollViewDelegate
是Object.values(req).filter(ele=>{
if((ele instanceof Object) && !(ele instanceof Array)){
return ele
}
})
的
req
答案 1 :(得分:1)
由于您只想map
只使用属性one
和two
,那么我们可以将它们用于flatMap
方法的参数中以获得所需的结果:
const result = friends.flatMap(({one, two}) =>([{...one}, {...two}]));
一个例子:
let friends = [
{
one: {
id: 'one',
address: 'something'
},
two: {
id: 'two',
roomID: 'something'
},
me: 'three'
}
];
const result = friends.flatMap(({one, two}) =>([{...one}, {...two}]));
console.log(result);
答案 2 :(得分:0)
这是个快速兵。
Object.keys(friends[0]).map(key => Object.prototype.toString.call(friends[0][key]) === '[object Object]' ? friends[0][key] : null).filter(x => x)