我具有以下格式的数据:如果要删除“ 2019-06-28”怎么办?
我通过此代码制作数据
let obj = this.state._markedDates.reduce((c, v) => Object.assign(c, {
[v]: {
selected: true,
marked: true
}
}), {});
this.setState({marked: obj});
现在我要删除对象内部的任何人都可以帮助我吗?我使代码在本机反应中
Object {
"2019-06-20": Object {
"marked": true,
"selected": true,
},
"2019-06-28": Object {
"marked": true,
"selected": true,
},
}
答案 0 :(得分:0)
您可以从对象中删除键
const a = {
"2019-06-20": {
"marked": true,
"selected": true,
},
"2019-06-28": {
"marked": true,
"selected": true,
},
};
Object.keys(a).forEach(keyToBeDeleted => {
// keyToBeDeleted has `2019-06-20` and `2019-06-28`
if (keyToBeDeleted === '2019-06-28') {
delete a[keyToBeDeleted]; // this will delete the key in your object as it is in loop. Treat your logic as per your requirements
}
})
答案 1 :(得分:0)
public static byte[] ReplaceBytes(byte[] src, byte[] search, byte[] repl)
{
if (repl == null) return src;
int index = FindBytes(src, search);
if (index < 0) return src;
byte[] dst = new byte[src.Length - search.Length + repl.Length];
Buffer.BlockCopy(src, 0, dst, 0, index);
Buffer.BlockCopy(repl, 0, dst, index, repl.Length);
Buffer.BlockCopy(src, index + search.Length, dst, index + repl.Length,src.Length - (index + search.Length));
return dst;
}
public static int FindBytes(byte[] src, byte[] find)
{
if(src==null|| find==null|| src.Length==0|| find.Length == 0 || find.Length> src.Length) return -1;
for (int i = 0; i < src.Length - find.Length +1 ; i++)
{
if (src[i] == find[0])
{
for(int m=1;m< find.Length;m++)
{
if (src[i + m] != find[m]) break;
if (m == find.Length - 1) return i;
}
}
}
return -1;
}